/*
 * p2631.cpp
 *
 *  Created on: 2013-7-24
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 10005;
vector<int> son[maxn], len[maxn];
int len1, vv, ans;//len1,v:第一次dfs所用的最值和最远节点
void dfs(int u, int pa, int L)
{
	if (son[u].size() == 1 && u != 1)
	{
		if (L > len1)
		{
			len1 = L;
			vv = u;
		}
		return;
	}
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i];
		if (v != pa)
			dfs(v, u, L + len[u][i]);
	}

}
void dfs2(int u, int pa, int L)
{
	if (son[u].size() == 1 && u != vv)
	{
		ans = max(ans, L);
		return;
	}
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i];
		if (v != pa)
			dfs2(v, u, L + len[u][i]);
	}
}
int main()
{
	int x, y, l;
	while (scanf("%d%d%d", &x, &y, &l) != EOF)
	{
		son[x].push_back(y);
		son[y].push_back(x);
		len[x].push_back(l);
		len[y].push_back(l);
	}
	len1 = 0;
	vv = 1;
	dfs(1, 0, 0);
	ans = 0;
	dfs2(vv, 0, 0);
	printf("%d\n",ans);
	return 0;
}
